package com.ruoyi.web.controller.store;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.CommonPage;
import com.ruoyi.common.CommonResult;
import com.ruoyi.store.domain.HmSystemFormTemp;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.store.vo.HmSystemFormTempVo;
import com.ruoyi.store.bo.HmSystemFormTempQueryBo;
import com.ruoyi.store.bo.HmSystemFormTempAddBo;
import com.ruoyi.store.bo.HmSystemFormTempEditBo;
import com.ruoyi.store.service.IHmSystemFormTempService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 表单配置Controller
 *
 * @author ruoyi
 * @date 2021-07-04
 */
@Api(value = "表单配置控制器", tags = {"表单配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/store/form/temp")
public class HmSystemFormTempController extends BaseController {

	private final IHmSystemFormTempService iHmSystemFormTempService;


	/**
	 * 查询表单配置列表
	 */
	@ApiOperation("查询表单配置列表")
	@PreAuthorize("@ss.hasPermi('store:temp:list')")
	@GetMapping("/list")
	public TableDataInfo<HmSystemFormTempVo> list(@Validated HmSystemFormTempQueryBo bo) {
		return iHmSystemFormTempService.queryPageList(bo);
	}

	/**
	 * 导出表单配置列表
	 */
	@ApiOperation("导出表单配置列表")
	@PreAuthorize("@ss.hasPermi('store:temp:export')")
	@Log(title = "表单配置", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<HmSystemFormTempVo> export(@Validated HmSystemFormTempQueryBo bo) {
		List<HmSystemFormTempVo> list = iHmSystemFormTempService.queryList(bo);
		ExcelUtil<HmSystemFormTempVo> util = new ExcelUtil<HmSystemFormTempVo>(HmSystemFormTempVo.class);
		return util.exportExcel(list, "表单配置");
	}

	/**
	 * 获取表单配置详细信息
	 */
	@ApiOperation("获取表单配置详细信息")
	@PreAuthorize("@ss.hasPermi('store:temp:query')")
	@GetMapping("/{id}")
	public AjaxResult<HmSystemFormTempVo> getInfo(@NotNull(message = "主键不能为空")
												  @PathVariable("id") Long id) {
		return AjaxResult.success(iHmSystemFormTempService.queryById(id));
	}

	/**
	 * 新增表单配置
	 */
	@ApiOperation("新增表单配置")
	@PreAuthorize("@ss.hasPermi('store:temp:add')")
	@Log(title = "表单配置", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody HmSystemFormTempAddBo bo) {
		return toAjax(iHmSystemFormTempService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改表单配置
	 */
	@ApiOperation("修改表单配置")
	@PreAuthorize("@ss.hasPermi('store:temp:edit')")
	@Log(title = "表单配置", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody HmSystemFormTempEditBo bo) {
		return toAjax(iHmSystemFormTempService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除表单配置
	 */
	@ApiOperation("删除表单配置")
	@PreAuthorize("@ss.hasPermi('store:temp:remove')")
	@Log(title = "表单配置" , businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iHmSystemFormTempService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
